<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AppUserRecharge extends Model
{
    use HasFactory;

    public static $model_type = [
        1   => '用户充值',
        2   => '拍卖扣除',
        3   => '用户转出',
    ];

    protected $fillable = [
        'id','user_id','type','amount'
    ];

    protected static function booted()
    {
        static::created(function ($model){

            $flag = AppUser::find($model->user_id);
            $flag->balance = $flag->balance + intval($model->amount);
            $flag->save();

        });
    }
}
